import Loading from '@/components/common/Loading.vue'
import { createApp } from 'vue'

let loading=null
const createLoading=(el:HTMLElement) =>{
  loading=createApp(Loading)
  el.style.position='relative'
  const fragment:any=document.createDocumentFragment()
  loading.mount(fragment)
  el.appendChild(fragment)
}
const destoryLoading=(el:HTMLElement) =>{
  if(!loading) return
  el.removeAttribute('style')
  loading.unmount()
}
export default {
  mounted(el:HTMLElement, binding) {
    createLoading(el)
  },
  updated(el:HTMLElement, binding){
    if(binding.value==binding.oldValue) return
    if(!binding.value){
      destoryLoading(el)
    }else{
      createLoading(el)
    }
  }
}